package cn.stazxr.listener;

import java.awt.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

/**
 * Package: cn.stazxr.listener
 * Listener
 *
 * @Author: stazxr
 * @Create: 2023/12/2
 * @Version: v1.0
 **/
public class ListenerTest {
    public static void main(String[] args) {
        Frame frame = new Frame("Hello World!");
        frame.setBounds(500, 300, 500, 300);
        frame.setAlwaysOnTop(true);

        frame.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                System.out.println("Hello World!");
                frame.dispose();
            }
        });

        frame.addKeyListener(new KeyAdapter() {
            @Override
            public void keyTyped(KeyEvent e) {
                System.out.println(e.getKeyChar());
            }
        });

        frame.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                System.out.println(e.getX() + "," + e.getY() + ":" + e.getButton());
            }
        });
        frame.setVisible(true);
    }
}
